﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MailList.ascx.cs" Inherits="Zebra.Umbraco.Marcos.MailList.MailList" %>
<form id="Form2" runat="server" style="width: 620px">
<div id="foobar" style="padding: 15px; display: none">
    <asp:TextBox ID="TextBox1" Columns="50" runat="server" ClientIDMode="Static"></asp:TextBox><div
        id="emptyStar" style="visibility: hidden">
        *</div>
    <asp:Button ID="Button1" OnClientClick=" return test();" CssClass="button" runat="server"
        ValidationGroup="G1" Text="创建" OnClick="Button1_Click" Style="height: 26px" ClientIDMode="Static" />
    <div id="foobar2" style="visibility: hidden">
        <span style="color: Red" id="errorText">已存在同名地址簿</span></div>
</div>
<p>
    <input id="open-custom-dialog" class="button" type="button" value="新建地址簿" />
</p>
<p>
    <asp:GridView CssClass="MailListTable" ID="GridView1" runat="server" AutoGenerateColumns="False"
        AllowPaging="True" OnRowCommand="GridView1_RowCommand">
        <Columns>
            <asp:BoundField HeaderStyle-Width="200" HeaderText="地址簿" DataField="Name" />
            <asp:BoundField HeaderStyle-Width="60" HeaderText="邮件数量" />
            <asp:BoundField HeaderStyle-Width="50" HeaderText="创建日期" DataFormatString="{0:yyyy/MM/dd}"
                DataField="RowCreatedOn" />
            <asp:BoundField HeaderStyle-Width="50" HeaderText="修改日期" DataFormatString="{0:yyyy/MM/dd}"
                DataField="RowModifiedOn" />
            <asp:TemplateField HeaderStyle-Width="60" HeaderText="操作">
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "/MailList/" + Eval("MailListID")+"/Detail.aspx"  %>'>详细</asp:HyperLink>
                    <asp:LinkButton ID="LinkButton2" runat="server" CommandArgument='<%# Eval("MailListID")  %>'
                        CommandName="Remove" OnClientClick="return confirm('是否确定要删除此地址簿');">删除</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</p>
</form>
<script>
    (function ($) {
        $(function () {
            $("#open-custom-dialog").click(function () {
                $.dialog({
                    title: "新建地址簿",
                    btns: ["cancel"],
                    defaultBtn: "cancel",
                    contentBtnHelp: true,
                    className: "custom-dialog",
                    content: $("#foobar"),
                    father: "#Form2"
                })
            });
        });
    })(jQuery);
    var testVal = false;
    var testText;
    var validationDone = false;
    function test() {
        if ($("#TextBox1").val().trim() == "") {
            $("#emptyStar").css("visibility", "");
            return false;
        } else {
            $("#emptyStar").css("visibility", "hidden");
        }
        if (!validationDone) {
            testText = $("#TextBox1").val()
            var rr = '/maillist/check/' + testText;
            $.ajax({
                url: rr,
                type: 'GET',
                error: function () {
                    validationDone = true;
                    testVal = true;
                    $("#Button1").click();

                },
                success: function (xml) {
                    validationDone = true;
                    $("#foobar2").css("visibility", "");
                    testVal = false;

                }
            });
            return false;
        } else {
            if (testText == $("#TextBox1").val()) {
                return testVal;
            } else {
                validationDone = false;
                return test();
            }
        }
    }
     
      
  
</script>
